/*
 * MATSUM.cxx
 *
 *  Created on: 8:31:56 PM Oct 31, 2012
 *      Author: Pallab
 * "I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait(double seconds) {
	double endtime = clock() + (seconds * CLOCKS_PER_SEC);
	while (clock() < endtime) {
		;
	}
}
#define T int
inline T fastIn() {
	register char c = 0;
	register T a = 0;
	bool neg = false;
	while (c < 33)
		c = getchar();
	while (c > 33) {
		if (c == '-') {
			neg = true;
		} else {
			a = (a * 10) + (c - '0');
		}
		c = getchar();
	}
	return neg ? -a : a;
}
const int MX = 1024 + 10;
int R;
char buff[10];
int vi[4];
inline void read() {
	R = fastIn();
}

//1 based indexing
namespace BIT {
const int maxn = MX;
int Tree[maxn][maxn];
inline void init() {
	SET(Tree, 0);
}
inline void Add(int idx, int idy, int S) {
	int y2 = idy;
	while (idx <= maxn) {
		idy = y2;
		while (idy <= maxn) {
			Tree[idx][idy] += S;
			idy += (idy & -idy);
		}
		idx += (idx & -idx);
	}
}
inline int query(int idx, int idy) {
	int y2 = idy;
	int ret = 0;
	while (idx > 0) {
		idy = y2;
		while (idy > 0) {
			ret += Tree[idx][idy];
			idy -= (idy & -idy);
		}
		idx -= (idx & -idx);
	}
	return ret;
}
inline void Set(int idx, int idy, int newval) {
	int l = idx, b = idy, r = idx, t = idy;
	int oldval = query(r, t) - query(l - 1, t) - query(r, b - 1)
			+ query(l - 1, b - 1);
	Add(idx, idy, -oldval);
	Add(idx, idy, newval);
}
}
inline void proc() {
	BIT::init();
	while (scanf(" %s", buff) == 1) {
		if (strcmp(buff, "SET") == 0) {
			fo(i,3)
				vi[i] = fastIn();
			BIT::Set(vi[0] + 1, vi[1] + 1, vi[2]);
		} else if (strcmp(buff, "SUM") == 0) {
			fo(i,4)
				vi[i] = fastIn() + 1;
			int total = BIT::query(vi[2], vi[3]) - BIT::query(vi[0] - 1, vi[3])
					- BIT::query(vi[2], vi[1] - 1)
					+ BIT::query(vi[0] - 1, vi[1] - 1);
			cout << total << '\n';
		} else {
			break;
		}
	}
}
int main() {
	int kase = 1;
#if defined( xerxes_pc )
	if (!freopen("in1", "r", stdin))
		puts("error opening file in "), assert(0);
	kase = 1;
#endif
	kase = fastIn();
	fo(i,kase)
	{
		read();
		proc();
	}
	return 0;
}
